# -*- coding: utf-8 -*-
from openerp.osv import fields,osv
from openerp import tools
from openerp.tools.translate import _
from openerp.modules.registry import RegistryManager

class pm_parameter_category(osv.osv):
    _name = 'pm.parameter.category'
    _columns = {
        'name':fields.char(string='Category', size=100, required=True),
        'code':fields.char(string='Code', size=100,required=True),
        'remark':fields.text(string='Remark'),
        'parameters':fields.one2many('pm.parameter','category_id',string='Parameters'),
    }
    _sql_constraints = [('code_unique','unique(code)','Code must be unique!')]
pm_parameter_category()

class pm_parameter(osv.osv):
    _name = 'pm.parameter'
    _columns = {
        'category_id':fields.many2one('pm.parameter.category',string='Category'),
        'category_code':fields.related('category_id','code',type='char',string='Category code',store=True),
        'name':fields.char(string='Name', size=100, required=True),
        'code':fields.char(string='Code', size=100,required=True),
        'remark':fields.text(string='Remark'),
    }
    _sql_constraints = [('code_unique','unique(code)','Code must be unique!')]
pm_parameter()

class pm_project(osv.osv):
    _name = 'pm.project'

    _columns = {
        'design_unit':fields.many2one('res.partner',string='设计单位',domain="[('is_company','=',True)]",help='设计单位'),
        'contruction_unit':fields.many2one('res.partner',string='施工单位',domain="[('is_company','=',True)]",help='施工单位'),
        'company':fields.many2one('res.partner',string='所属公司',domain="[('is_company','=',True)]",help='所属公司'),
        'name':fields.char(string='项目名称',size=300,required=True),
        'code':fields.char(string='项目编号', size=100,required=True),
        'source':fields.char(string='项目来源',size=100),
        'plot_code':fields.char(string='地块编号',help='Plot code', size=100),
        'plot_area':fields.float(string='土地面积',help='Plot area'),
        'plot_license':fields.char(string='土地许可证',help='Plot license',size=100),
        'plot_starttime':fields.datetime(string='使用期限从',help='Plot starttime'),
        'plot_endtime':fields.datetime(string='到',help='Plot endtime'),
        'plot_useage':fields.char(string='土地用途',help='Plot useage', size=200),
        'plot_shape':fields.char(string='土地形状',help='Plot shape',size=100),
        #容积率
        'plot_ratio':fields.char(string='容积率',help='Plot ratio',size=100),
        'plot_card_no':fields.char(help='Plot card no',size=100,string='房地产证号'),
        'plot_rent_no':fields.char(help='Plot rent no',size=100,string='外租许可证'),
        'plot_prepare_sale_no':fields.char(help='Plot save no',size=100,string='预售许可证'),
        'plot_address':fields.char(string='具体地址',help='Plot address',size=200),
        'remark':fields.text(string='备注'),
        'project_areas':fields.one2many('pm.project.area','project_id',string='分区',help='Project area'),
        'plot_address_map':fields.char(string='地图经纬度'),
        
    }
pm_project()

class pm_project_area(osv.osv):
    _name = 'pm.project.area'

    _columns = {
        'project_id':fields.many2one('pm.project',string='Project'),
        'name':fields.char(string='区域名称', size=100,required=True),
        'code':fields.char(string='区域编号', size=100 ),
        'remark':fields.text(string='备注'),
        'plot_address_map':fields.char(string='图片坐标'),
        'project_buildings':fields.one2many('pm.project.building','project_area_id',string='楼栋'),
    }
pm_project_area()


class pm_project_building(osv.osv):
    _name = 'pm.project.building'

    _columns = {
        'name':fields.char(help='Name', size=100,required=True,string='楼栋名称'),
        'code':fields.char(help='Code',size=100,required=True,string='楼栋编码'),
        'project_id':fields.many2one('pm.project',help='Project',string='项目名称'),
        'project_area_id':fields.many2one('pm.project.area',help='Area',domain="[('project_id','=',project_id)]",string='所属分区'),
        'ground_floor_count':fields.integer(help='Ground floor count',string='地上楼层数'),
        'under_floor_count':fields.integer(help='Under floor count',string='地下楼层数'),
        'height':fields.float(help='Building height',string='楼高'),
        'goverment_no':fields.char(help='Goverment no',string='行政编号'),
        'type':fields.many2one('pm.parameter',help='Type',domain="[('category_code','=','FXLB')]",string='房型类别'),
        'finish_date':fields.date(help='Finish date',string='竣工日期'),
        'in_date':fields.date(help='In date',string='入住日期'),
        'building_company':fields.many2one('res.partner',help='Building company',string='施工单位'),
        'area':fields.float(help='Area',string='占地面积'),
        'structure':fields.many2one('pm.parameter',help='Structure',domain="[('category_code','=','JZJG')]",string='建筑结构'),
        'direction':fields.many2one('pm.parameter',help='Direction',domain="[('category_code','=','FJCX')]",string='房间朝向'),
        'address':fields.char(help='Address',string='具体地址'),
        'pic_src':fields.char(string='图片路径'),
        'plot_pic_map':fields.char(string='图片坐标'),
        'remark':fields.text(string='备注'),
    }
pm_project_building()

class pm_project_building_unit(osv.osv):
    _name = 'pm.project.building.unit'

    _columns = {
        'building_id':fields.many2one('pm.project.building',string='Building',help='所属楼栋'),
        'name':fields.char(string='Name',size=100,help='单元名称'),
        'code':fields.char(string='Code',size=100,help='单元编号'),
        'remark':fields.char(string='Remark',size=200,help='备注'),
    }
pm_project_building_unit()

"""
class pm_project_building_hoursetype(osv.osv):
    _name = 'pm.project.building.hoursetype'
    
    _columns = {
        'building_id':fields.many2one('pm.project.building',string='Building',help='所属楼栋'),
        'name':fields.char(string='Name',size=100,help='名称'),
        'code':fields.char(string='Code',size=100,help='编号'),
        'remark':fields.char(string='Remark',size=200,help='备注'),
    }
pm_project_building_hoursetype()

class pm_project_building_floor(osv.osv):
    _name = 'pm.project.building.floor'
    
    _columns = {
        'building_id':fields.many2one('pm.project.building',string='Building',help='建筑'),
        'name':fields.char(string='Name',size=100,help='名称'),
        'code':fields.char(string='Code',size=100,help='编号'),
        'remark':fields.char(string='Remark',size=200,help='备注'),
    }
pm_project_building_floor()
"""

class pm_project_building_room(osv.osv):
    _name = 'pm.project.building.room'
    _columns = {
        'name':fields.char(help='房间编号', size=100,required=True,string='房间编号'),
        'receive_object':fields.selection([('owner','业主'),('rent','租户'),('no','无')],string='收费服务对象'),
        'hourseholder':fields.many2one('res.partner',string='当前住户',help='房间的收费对象'),
        'property_owner':fields.many2one('res.partner',string='业主',help='Propery owner'),
        'project_id':fields.many2one('pm.project',string='所属项目'),
        'area_id':fields.many2one('pm.project.area',string='所属区域',domain="[('project_id','=',project_id)]"),
        'building_id':fields.many2one('pm.project.building',string='所属楼栋',help='Building',domain="[('project_area_id','=',area_id)]"),
        'order_number':fields.integer(string='房间顺序号',help='Order number'),
        'building_area':fields.float(string='建筑面积',help='Building area'),
        'inner_area':fields.float(string='套内面积',help='Inner area'),
        'hourse_state':fields.many2one('pm.parameter',string='房间状态',domain="[('category_code','=','FJZT')]"),
        'hourse_type':fields.many2one('pm.parameter',string='房间类型',domain="[('category_code','=','FJLX')]"),
        'hand_standard':fields.many2one('pm.parameter',string='装修标准',domain="[('category_code','=','ZXBZ')]"),
        'direction':fields.many2one('pm.parameter',string='房间朝向',domain="[('category_code','=','FJCX')]"),
        'hourse_form':fields.many2one('pm.parameter',string='房间户型',domain="[('category_code','=','FJFX')]"),
        'floor':fields.integer(string='所在楼层'),
        'unit':fields.char(string='所属单元',size=100,help='Unit'),
        'closing_date':fields.date(string='接房日期'),
        'hand_date':fields.date(string='装修日期'),
        'in_start_date':fields.date('入住起始日期'),
        'in_end_date':fields.date('入住结束日期'),
        'address':fields.char(string='地址',size=200),
        'is_charge':fields.boolean(string='是否收费'),
        'remark':fields.text(string='备注'),
        'cost_item_rooms':fields.one2many('pm.cost.item.room','room_id',string='房间收费项'),
    }
pm_project_building_room()
